#include <allegro.h>
#include <stdio.h>
#include "race.h"

int main () {

	int position = 0;
	int c1, c2;

	BITMAP *Buffer;
	BITMAP *Background=NULL;
        
        Car car;
	Car car_r;

        allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}
        
        Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	Background = load_background_bmp(Background);
	//draw_background(Background,Buffer);
    
	load_cars(&car, &car_r);
           
	//blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	init_cars(&car,&car_r);
	//draw_background(Background,Buffer);


        while (!key[KEY_ESC]) 
	{
		

			move_background(Background, &position,Buffer);
		clear_bitmap(Buffer);
		draw_background(Background,Buffer,position);
		draw_cars(&car, &car_r,Buffer);
              
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		move_cars(&car, &car_r,position,Background,Buffer);
		win_lose(c1,c2, position,Buffer);
	}		

	readkey();
	destroy_cars(&car, &car_r);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);


}
END_OF_MAIN();
